<?php
/**
 * 商场活动
 * @author ice<iceinto@mallog.com.cn>
 */
class MallAction extends CommonAction
{
    public function _initialize()
    {
        parent::_initialize();
        if ($this->_role['role_id'] != 5) {
            $this->errorLang('_NOT_ACCESS');
        }
        $this->assign('nav', 10);
    }

    public function index()
    {
        //获取商场列表
        $MallModel = D('Mall');
        $malls = $MallModel->getList();
        $this->assign('malls', $malls);
        $this->display();
    }

    /**
     * 获取商场楼层信息
     * @author ice <iceinto@mallog.com.cn>
     */
    public function getFloors()
    {
        $mid = intval(getGet('mid'));
        $floors = D('Mall')->getFloorList($mid, 'id,mid,sain as name');
        $this->assign('floors', $floors);
        $this->ajaxReturn($this->fetch(), null, 1);
    }

    /**
     * 获取商场楼层品牌
     * @author ice <iceinto@mallog.com.cn>
     */
    public function getBrands()
    {
        $brands = array();
        $status = 1;
        $fid = intval(getGet('fid'));
        $TaskModel = D('Task');
        $QueueModel = D('Queue');
        $time = time();
        $brands = D('Mall')->getFloorBrandList($fid);
        if ($brands) {
            $status = 1;
            // Get brand task
            foreach ($brands as $key => $brand) {
                $activity = $TaskModel->getBrandLastActivity($brand ['mid'], $fid, $brand ['id']);
                $brands [$key] ['activity'] = $activity;
                if ($activity) {
                    if ($activity['status'] != 100 && $activity['status'] != 1) {
                        $brands[$key]['activity']['status'] = $QueueModel->getStatusById($activity['id']);
                    } else {
                        $brands[$key]['activity']['status'] = $activity['status'];
                    }
                    $brands [$key] ['activity'] ['status_info'] = $QueueModel->getStatus($brands [$key] ['activity'] ['status']);
                    $color = 'green';
                    if ($brands [$key] ['activity'] ['end_time'] < $time) {
                        $color = 'red';
                    }
                    $brands [$key] ['activity'] ['color'] = $color;
                }
            }
        }
        $this->assign('fid', $fid);
        $this->assign('brands', $brands);
        $this->ajaxReturn($this->fetch(), null, $status);
    }
}

?>